<!DOCTYPE html>
<html lang="zh-CN" class="light">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}cr文档管理系统{% endblock %}</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/echarts/5.4.3/echarts.min.js"></script>
    <style>
        :root {
            --primary-color: #667eea;
            --secondary-color: #764ba2;
            --success-color: #48bb78;
            --warning-color: #ecc94b;
            --danger-color: #f56565;
            --info-color: #4299e1;
            --gradient-start: #e0e7ff;
            --gradient-end: #dbeafe;
            --card-bg: rgba(255, 255, 255, 0.8);
        }
        
        .dark {
            --bg-primary: #1a1a1a;
            --bg-secondary: #2d2d2d;
            --bg-tertiary: #363636;
            --text-primary: #ffffff;
            --text-secondary: #a0aec0;
            --border-color: #4a5568;
            --gradient-start: #1e1b4b;
            --gradient-end: #312e81;
            --card-bg: rgba(30, 41, 59, 0.8);
        }
        
        .light {
            --bg-primary: #ffffff;
            --bg-secondary: #f7fafc;
            --bg-tertiary: #edf2f7;
            --text-primary: #1a202c;
            --text-secondary: #4a5568;
            --border-color: #e2e8f0;
            --gradient-start: #e6e9f0;
            --gradient-end: #eef1f5;
        }
        
        body {
            background: linear-gradient(135deg, var(--gradient-start) 0%, var(--gradient-end) 100%);
            background-attachment: fixed;
            color: var(--text-primary);
            transition: all 0.3s ease;
            min-height: 100vh;
        }

        main {
            position: relative;
            z-index: 1;
        }

        main::before {
            content: '';
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: radial-gradient(circle at 50% 50%, rgba(99, 102, 241, 0.15), transparent 80%),
                        radial-gradient(circle at 80% 20%, rgba(244, 114, 182, 0.15), transparent 50%);
            pointer-events: none;
            z-index: -1;
        }
        
        .nav-link {
            position: relative;
            color: var(--text-secondary);
            transition: all 0.3s ease;
        }
        
        .nav-link:hover {
            color: var(--primary-color);
        }
        
        .nav-link::after {
            content: '';
            position: absolute;
            width: 0;
            height: 2px;
            bottom: -2px;
            left: 0;
            background-color: var(--primary-color);
            transition: width 0.3s ease;
        }
        
        .nav-link:hover::after {
            width: 100%;
        }
        
        .card {
            background: var(--card-bg);
            backdrop-filter: blur(12px);
            border: 1px solid rgba(255, 255, 255, 0.1);
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
            border-radius: 1rem;
            transition: all 0.3s ease;
        }
        
        .dark .card {
            background: rgba(26, 26, 26, 0.9);
        }
        
        .card:hover {
            transform: translateY(-2px);
            box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
        }
        
        .btn {
            padding: 0.5rem 1rem;
            border-radius: 0.5rem;
            transition: all 0.3s ease;
            cursor: pointer;
        }
        
        .btn-primary {
            background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
            color: white;
            text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
        }
        
        .btn-primary:hover {
            transform: translateY(-1px);
            box-shadow: 0 4px 6px -1px rgba(255, 178, 62, 0.4);
        }
        
        .toast {
            position: fixed;
            bottom: 1rem;
            right: 1rem;
            padding: 1rem;
            border-radius: 0.5rem;
            background: var(--bg-primary);
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
            z-index: 50;
            transition: all 0.3s ease;
            backdrop-filter: blur(12px);
        }
        
        .toast.success { border-left: 4px solid var(--success-color); }
        .toast.warning { border-left: 4px solid var(--warning-color); }
        .toast.error { border-left: 4px solid var(--danger-color); }
        .toast.info { border-left: 4px solid var(--info-color); }
        
        .modal {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 100;
            opacity: 0;
            visibility: hidden;
            transition: all 0.3s ease;
            backdrop-filter: blur(8px);
        }
        
        .modal.active {
            opacity: 1;
            visibility: visible;
        }
        
        .modal-content {
            background: var(--bg-primary);
            border-radius: 1rem;
            padding: 2rem;
            max-width: 90%;
            max-height: 90vh;
            overflow-y: auto;
            transform: translateY(-20px);
            transition: all 0.3s ease;
            border: 1px solid rgba(255, 255, 255, 0.1);
        }
        
        .modal.active .modal-content {
            transform: translateY(0);
        }
        
        .loading-spinner {
            width: 40px;
            height: 40px;
            border: 4px solid var(--bg-tertiary);
            border-top: 4px solid var(--primary-color);
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }
        
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        
        .tooltip {
            position: relative;
            display: inline-block;
        }
        
        .tooltip:hover::before {
            content: attr(data-tooltip);
            position: absolute;
            bottom: 100%;
            left: 50%;
            transform: translateX(-50%);
            padding: 0.5rem;
            background: var(--bg-tertiary);
            border-radius: 0.25rem;
            font-size: 0.875rem;
            white-space: nowrap;
            z-index: 10;
        }
        
        .progress-ring {
            transform: rotate(-90deg);
        }
        
        .progress-ring-circle {
            stroke: var(--primary-color);
            stroke-linecap: round;
            transition: stroke-dashoffset 0.3s ease;
        }
        
        .progress-ring-background {
            stroke: var(--bg-tertiary);
        }

        .drop-zone {
            background: var(--card-bg);
            backdrop-filter: blur(12px);
            border: 2px dashed var(--border-color);
            border-radius: 1rem;
            transition: all 0.3s ease;
        }

        .dark .drop-zone {
            background: rgba(26, 26, 26, 0.5);
        }

        .drop-zone:hover {
            background: rgba(255, 255, 255, 0.9);
            border-color: var(--primary-color);
        }

        .file-list {
            background: var(--card-bg);
            backdrop-filter: blur(12px);
            border-radius: 1rem;
            padding: 1rem;
        }

        .dark .file-list {
            background: rgba(26, 26, 26, 0.7);
        }

        nav {
            background: var(--card-bg);
            backdrop-filter: blur(12px);
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }

        .status-indicator {
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background-color: var(--primary-color);
            margin-right: 8px;
            display: inline-block;
            position: relative;
        }

        .status-indicator::after {
            content: '';
            position: absolute;
            width: 100%;
            height: 100%;
            border-radius: 50%;
            background-color: var(--primary-color);
            animation: pulse 2s infinite;
        }

        @keyframes pulse {
            0% {
                transform: scale(1);
                opacity: 0.8;
            }
            70% {
                transform: scale(2);
                opacity: 0;
            }
            100% {
                transform: scale(1);
                opacity: 0;
            }
        }
    </style>
    {% block head %}{% endblock %}
</head>
<body class="bg-gray-100 dark:bg-gray-900">
    <!-- 加载遮罩层 -->
    <div id="loading-overlay" class="fixed inset-0 bg-black bg-opacity-50 hidden items-center justify-center z-50">
        <div class="bg-white dark:bg-gray-800 rounded-lg p-4 flex items-center space-x-3">
            <div class="animate-spin rounded-full h-8 w-8 border-4 border-indigo-500 border-t-transparent"></div>
            <span class="text-gray-700 dark:text-gray-300">加载中...</span>
        </div>
    </div>

    <!-- 模态框容器 -->
    <div id="modal-container"></div>

    <nav class="bg-white/80 dark:bg-gray-800/80 shadow-lg backdrop-blur-md sticky top-0 z-50">
        <div class="max-w-7xl mx-auto px-4">
            <div class="flex justify-between h-16">
                <div class="flex items-center">
                    <a href="/" class="flex items-center space-x-3">
                        <svg class="w-8 h-8 text-primary" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
                        </svg>
                        <span class="text-xl font-bold text-gray-800 dark:text-white">cr文档管理系统</span>
                    </a>
                </div>
                
                {% if session.get('logged_in') %}
                <div class="flex items-center space-x-4">
                    <!-- 系统状态指示器 -->
                    <div class="flex items-center space-x-2">
                        <span class="status-indicator w-2 h-2 rounded-full bg-green-500"></span>
                        <span class="text-sm text-gray-600 dark:text-gray-300">系统正常</span>
                    </div>
                    
                    <!-- 登录信息 -->
                    <div class="flex items-center space-x-4 text-sm text-gray-600 dark:text-gray-300">
                        <div>
                            <i class="fas fa-clock mr-1"></i>
                            <span>{{ session.get('login_time', '') }}</span>
                        </div>
                        <div>
                            <i class="fas fa-network-wired mr-1"></i>
                            <span>{{ session.get('login_ip', '') }}</span>
                        </div>
                    </div>
                    
                    <!-- 通知中心 -->
                    <div class="relative">
                        <button id="notifications-toggle" class="p-2 rounded-full hover:bg-gray-100 dark:hover:bg-gray-700">
                            <svg class="w-6 h-6 text-gray-600 dark:text-gray-300" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9"/>
                            </svg>
                            <span class="notification-badge"></span>
                        </button>
                        
                        <div id="notifications-panel" class="hidden absolute right-0 mt-2 w-80 bg-white dark:bg-gray-800 rounded-lg shadow-xl">
                            <!-- 通知列表将由 JavaScript 动态填充 -->
                        </div>
                    </div>
                    
                    <!-- 用户菜单 -->
                    <div class="relative">
                        <button id="user-menu" class="flex items-center space-x-2">
                            <img class="w-8 h-8 rounded-full bg-gray-300" src="https://www.gravatar.com/avatar/?d=mp" alt="用户头像">
                            <span class="text-sm text-gray-700 dark:text-gray-300">管理员</span>
                            <svg class="w-4 h-4 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
                            </svg>
                        </button>
                        
                        <div id="user-menu-dropdown" class="hidden absolute right-0 mt-2 w-48 bg-white dark:bg-gray-800 rounded-lg shadow-xl z-50">
                            <div class="px-4 py-3 border-b border-gray-200 dark:border-gray-700">
                                <p class="text-sm text-gray-700 dark:text-gray-300">登录信息</p>
                                <p class="text-xs text-gray-500 dark:text-gray-400 mt-1">
                                    <i class="fas fa-clock mr-1"></i>{{ session.get('login_time', '') }}
                                </p>
                                <p class="text-xs text-gray-500 dark:text-gray-400 mt-1">
                                    <i class="fas fa-network-wired mr-1"></i>{{ session.get('login_ip', '') }}
                                </p>
                                <p class="text-xs text-gray-500 dark:text-gray-400 mt-1">
                                    <i class="fas fa-server mr-1"></i>{{ session.get('login_hostname', '') }}
                                </p>
                            </div>
                            <a href="#" class="block px-4 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700" onclick="showChangePasswordModal()">
                                <i class="fas fa-key mr-2"></i>修改密码
                            </a>
                            <a href="#" class="block px-4 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700" onclick="showLoginRecords()">
                                <i class="fas fa-history mr-2"></i>登录记录
                            </a>
                            <a href="#" class="block px-4 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700" onclick="showSystemSettings()">
                                <i class="fas fa-cog mr-2"></i>系统设置
                            </a>
                            <div class="border-t border-gray-200 dark:border-gray-700">
                                <a href="{{ url_for('auth.logout') }}" class="block px-4 py-2 text-sm text-red-600 hover:bg-gray-100 dark:hover:bg-gray-700">
                                    <i class="fas fa-sign-out-alt mr-2"></i>退出登录
                                </a>
                            </div>
                        </div>
                    </div>
                    
                    <!-- 主题切换 -->
                    <button id="theme-toggle" class="p-2 rounded-full hover:bg-gray-100 dark:hover:bg-gray-700">
                        <svg class="w-6 h-6 text-gray-600 dark:text-gray-300" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z"/>
                        </svg>
                    </button>
                </div>
                {% endif %}
            </div>
        </div>
    </nav>

    <main class="container mx-auto px-4 py-8">
        {% with messages = get_flashed_messages(with_categories=true) %}
            {% if messages %}
                {% for category, message in messages %}
                    <div class="toast {{ category }} mb-4">
                        <div class="flex items-center">
                            {% if category == 'success' %}
                                <i class="fas fa-check-circle text-green-500 mr-2"></i>
                            {% elif category == 'error' %}
                                <i class="fas fa-exclamation-circle text-red-500 mr-2"></i>
                            {% elif category == 'warning' %}
                                <i class="fas fa-exclamation-triangle text-yellow-500 mr-2"></i>
                            {% else %}
                                <i class="fas fa-info-circle text-blue-500 mr-2"></i>
                            {% endif %}
                            {{ message }}
                        </div>
                    </div>
                {% endfor %}
            {% endif %}
        {% endwith %}
        
        {% block content %}{% endblock %}
    </main>

    <footer class="bg-white/80 dark:bg-gray-800/80 shadow-lg backdrop-blur-md mt-8">
        <div class="container mx-auto px-4 py-6">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="text-center md:text-left mb-4 md:mb-0">
                    <p class="text-sm text-gray-600 dark:text-gray-400">
                        &copy; 2024 cr文档管理系统. All rights reserved.
                    </p>
                </div>
                <div class="flex space-x-4">
                    <a href="https://gitee.com/CRGOGOGO/upload.git" class="text-gray-600 dark:text-gray-400 hover:text-primary" target="_blank" title="访问 Gitee 仓库">
                        <i class="fab fa-git-alt"></i>
                    </a>
                </div>
            </div>
        </div>
    </footer>

    {% block scripts %}{% endblock %}
    <script src="{{ url_for('static', filename='js/main.js') }}"></script>
    <script>
        // 主题切换功能
        document.addEventListener('DOMContentLoaded', function() {
            const html = document.documentElement;
            const themeToggle = document.getElementById('theme-toggle');
            
            if (!themeToggle) return; // 如果元素不存在，直接返回
            
            const isDark = localStorage.getItem('theme') === 'dark';
            
            if (isDark) {
                html.classList.add('dark');
            }

            function updateThemeIcon() {
                if (!themeToggle) return; // 再次检查元素是否存在
                
                const isDarkMode = html.classList.contains('dark');
                themeToggle.innerHTML = isDarkMode ? 
                    '<svg class="w-6 h-6 text-yellow-400" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z"/></svg>' :
                    '<svg class="w-6 h-6 text-gray-800" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z"/></svg>';
            }

            themeToggle.addEventListener('click', () => {
                html.classList.toggle('dark');
                localStorage.setItem('theme', html.classList.contains('dark') ? 'dark' : 'light');
                updateThemeIcon();
            });

            updateThemeIcon();
        });
    </script>
</body>
</html> 